import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";

/**
 * Logo
 * @date 2019-02-28
 */
import React from 'react';
import { Icon } from 'antd';
import { Link } from 'dva/router';
import defaultLogo from "../../../assets/cpaas-default-favicon.png";
/**
 * @param {string} logo - logo
 * @param {boolean} collapsed - 是否需要缩放
 * @param {string} - title 标题
 * @param {object} styles - 传进来的样式 需要包含 logo, logo title, logo icon-img, logo icon-icon
 */

var DefaultHeaderLogo = /*#__PURE__*/function (_React$Component) {
  _inherits(DefaultHeaderLogo, _React$Component);

  var _super = _createSuper(DefaultHeaderLogo);

  function DefaultHeaderLogo() {
    _classCallCheck(this, DefaultHeaderLogo);

    return _super.apply(this, arguments);
  }

  _createClass(DefaultHeaderLogo, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          _this$props$logo = _this$props.logo,
          logo = _this$props$logo === void 0 ? defaultLogo : _this$props$logo,
          collapsed = _this$props.collapsed,
          title = _this$props.title,
          _this$props$styles = _this$props.styles,
          styles = _this$props$styles === void 0 ? {} : _this$props$styles;
      var logoClassNames = [styles.logo];

      if (collapsed) {
        logoClassNames.push(styles.collapsed);
      }

      return /*#__PURE__*/React.createElement("div", {
        className: logoClassNames.join(' ')
      }, /*#__PURE__*/React.createElement(Link, {
        to: "/"
      }, this.renderIcon(logo), !collapsed && /*#__PURE__*/React.createElement("h1", {
        className: styles.title,
        title: title
      }, title)));
    }
  }, {
    key: "renderIcon",
    value: function renderIcon(icon) {
      var _this$props$styles2 = this.props.styles,
          styles = _this$props$styles2 === void 0 ? {} : _this$props$styles2;

      if (typeof icon === 'string' && (icon.startsWith('http') || icon.startsWith('data:'))) {
        return /*#__PURE__*/React.createElement("img", {
          src: icon,
          alt: "",
          className: styles['icon-img']
        });
      }

      if (typeof icon === 'string') {
        return /*#__PURE__*/React.createElement(Icon, {
          type: icon,
          className: styles['icon-icon']
        });
      }

      return icon;
    }
  }]);

  return DefaultHeaderLogo;
}(React.Component);

export default DefaultHeaderLogo;